package kr.or.eclipse.dine.internal.util;

import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Status;
import org.eclipse.core.runtime.jobs.Job;

/**
 * {@link Process}가 지정된 시간까지 종료되지 않을 경우 강제로 종료하기 위한 {@link Job}.
 * 
 * @author Jeeeyul
 * 
 */
public class ProcessKiller extends Job {
    private Process process;

    public ProcessKiller(Process process) {
        super("Kill Process");
        this.process = process;
        setSystem(true);
    }

    @Override
    protected IStatus run(IProgressMonitor monitor) {
        try {
            this.process.exitValue();
        } catch (IllegalThreadStateException e) {
            this.process.destroy();
        }
        return Status.OK_STATUS;
    }
}
